<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <!-- 3.使用子组件 -->
        <count-cpn></count-cpn>
        <count-cpn></count-cpn>
        <count-cpn></count-cpn>
        <count-cpn></count-cpn>
        <count-cpn></count-cpn>

    </div>
    <script src="./vue.js"></script>
    <!-- 1.子组件模板 -->
    <template id="count">
        <div>
            <button @click="sub">-</button>
            <span>{{num}}</span>
            <button @click="add">+</button>
        </div>
    </template>
    <script>
        let app = new Vue({
            el: "#app",
            data:{},
            // 2.注册子组件
            components:{
                "count-cpn":{
                    template:"#count",
                    data(){
                        return {
                            num:0
                        }
                    },
                    methods:{
                        add(){
                            this.num++;
                        },
                        sub(){
                            this.num--;
                        }
                    }
                }
            }
        })
    </script>
</body>

</html>